package com.snake.springboot.custom.service.impl.fileoss;


import com.snake.springboot.custom.api.model.fileoss.FileOSSModel;
import com.snake.springboot.custom.api.model.fileoss.OSSDelModel;
import com.snake.springboot.custom.api.model.fileoss.OSSUrlModel;
import com.snake.springboot.custom.api.response.fileoss.OSSPoliciesRsp;
import com.snake.springboot.custom.api.service.fileoss.OSSInstanceService;
import com.snake.springboot.custom.api.service.fileoss.OSSService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>OSS实例
 * 类{@code OSSInstanceServiceImpl} </br>
 * 创建时间2025/5/8 16:11
 * @author yangxt
 * @see
 */
@Service
public class OSSInstanceServiceImpl implements OSSInstanceService {
    private Map<String, OSSService> ossMap=new HashMap<>(2);
    @Autowired
    public OSSInstanceServiceImpl(List<OSSService> payStrategies){
        for (OSSService payStrategy : payStrategies) {
            ossMap.put(payStrategy.ossType(),payStrategy);
        }
    }


    @Override
    public OSSPoliciesRsp generatePolicies(String fileUrl, FileOSSModel ossModel) {
        OSSPoliciesRsp ossPoliciesRsp = ossMap.get(ossModel.getOssType()).generatePolicies(fileUrl, ossModel);
        return ossPoliciesRsp;
    }

    @Override
    public void delOssUrls(OSSDelModel delModel, FileOSSModel ossModel) {
        ossMap.get(ossModel.getOssType()).delOssUrls(delModel, ossModel);
    }

    @Override
    public String generatePresignedUrl(OSSUrlModel urlModel, FileOSSModel ossModel) {
        return ossMap.get(ossModel.getOssType()).generatePresignedUrl(urlModel, ossModel);
    }

    @Override
    public String videoFirstFrame(OSSUrlModel urlModel, FileOSSModel ossModel) {
         return ossMap.get(ossModel.getOssType()).videoFirstFrame(urlModel, ossModel);
    }
}
